package com.example.saiweisi.controller.systemAdminController;

import com.example.saiweisi.common.Result;
import com.example.saiweisi.controller.request.ClothesKindRequest;
import com.example.saiweisi.model.ClothesKind;
import com.example.saiweisi.service.interf.IClothesKindService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/clotheskind")
@RestController
@CrossOrigin
@Slf4j
public class ClothesKindController {
    @Autowired
    private IClothesKindService clothesKindService;
    /**
     * 查询所有的衣服种类
     * @return 返回json
     */
    @GetMapping("/getall")
    public Result getall() {
        return Result.success(clothesKindService.getall());
    }
    //分页查询所有会员种类
    @GetMapping("/page")
    public Result page(ClothesKindRequest clothesKindRequest) {
        return Result.success(clothesKindService.page(clothesKindRequest));
    }
    //添加会员种类
    @PostMapping("/add")
    public Result addclotheskind(@RequestBody ClothesKind clothesKind){
        clothesKindService.addclotheskind(clothesKind);
        return Result.success();
    }
    //删除会员种类
    @DeleteMapping("/delete{clothesKindId}")
    public Result deleteclotheskind(@PathVariable Integer clothesKindId){
        System.out.println(clothesKindId);
        clothesKindService.deleteclotheskind(clothesKindId);
        return Result.success();
    }
    //批量删除
    @PostMapping("/deletes")
    public Result deletesclotheskind(@RequestBody List<Integer> clothesKindIds){
        clothesKindService.deletesclotheskind(clothesKindIds);
        return Result.success();
    }
    //根据id查找会员种类信息并返回前端，作为修改表单数据携带
    @GetMapping("/{clothesKindId}")
    public Result getById(@PathVariable Integer clothesKindId){
        ClothesKind clothesKind=clothesKindService.getById(clothesKindId);
        return Result.success(clothesKind);
    }
    @PutMapping("/update")
    public Result updateclotheskind(@RequestBody ClothesKind clothesKind){
        clothesKindService.updateclotheskind(clothesKind);
        return Result.success();
    }
}
